package priv.pront.code.robot.roboCom_pri_2021.zhi;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-07-09 17:11
 */
public class 增一数 {

    static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static int n;
    public static void main(String[] args) throws IOException {
        st.nextToken();
        n = (int) st.nval;
        for (int i = 0; i < n; i++) {
            st.nextToken();
            String nn = (int) st.nval + "";
            if(nn.length() % 2 != 0){
                System.out.println(0);
                continue;
            }
            String before = nn.substring(0, nn.length() / 2);
            String after = nn.substring(nn.length() / 2);
            if (Integer.parseInt(before) + 1 != Integer.parseInt(after)) {
                System.out.println(0);
            } else if (Math.sqrt(Integer.parseInt(nn)) - (int)Math.sqrt(Integer.parseInt(nn))  != 0) {
                System.out.println(1);
            }else{
                System.out.println(2);
            }

        }

    }
}
